<template>
    <div class="app-container">
        <el-drawer :append-to-body="false" :modal-append-to-body="false" v-model="drawer"
            :title="`主单【${masterInfo.ibMasterNo}】关联明细列表`" direction="rtl" size="80%">
            <wms-form v-model:query-params="queryParams" :form-list="formList" @query="getList" label-width="88px"
                @export="handleExport">
            </wms-form>

            <wms-table class="table-click" :loading="loading" :data-list="ibDetailsList" :column="column"
                :columnResize="true" :pageInfo="queryParams" @get-list="getList" @row-click="handleRowClick" />
            <ib-task v-if="showTask" v-model="showTask" :detail-info="detailInfo" />
        </el-drawer>
    </div>
</template>

<script setup name="IbDetails">
import WmsTable from '@/components/WmsTable/index.vue'
import WmsForm from '@/components/WmsForm/index.vue'
import IbTask from './ibTask/index.vue'
import { listIbDetails, getIbDetails } from "@/api/wms/ibDetails";
import { data, column, formList } from './index.js'
import { ref, reactive, getCurrentInstance, onMounted } from "vue";

const { proxy } = getCurrentInstance();
const queryParams = reactive(data.queryParams);

const props = defineProps({
    masterInfo: {
        type: Object,
        require: true
    }
})
let drawer = defineModel(false)
const ibDetailsList = ref([]);
const loading = ref(false);

// 任务显示相关变量
let showTask = ref(false);
let detailInfo = ref({
    ibMasterId: null,
    ibDetailId: null
});

/** 查询入库明细单列表 */
function getList() {
    console.log('调用子组件,props.masterInfo', props.masterInfo);
    queryParams.ibMasterId = props.masterInfo.ibMasterId
    loading.value = true;
    listIbDetails(proxy.addDateRange(queryParams, queryParams.dateRange)).then(response => {
        ibDetailsList.value = response.rows;
        queryParams.total = response.total;
        loading.value = false;
    });
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    dateRange.value = [];
    proxy.resetForm("queryRef");
    handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
    proxy.download('wms/ibDetail/export', {
        ...queryParams
    }, `入库明细_${new Date().getTime()}.xlsx`)
}

/** 处理行点击事件，显示关联任务 */
function handleRowClick(row) {
    console.log('点击入库明细：', row);
    showTask.value = true;
    detailInfo.value = {
        ibMasterId: row.ibMasterId,
        ibDetailId: row.ibDetailId
    };
}
getList();
</script>
